package zozopo.warehouse;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import org.json.JSONObject;

import zozopo.warehouse.operations.GoodsOS;
import zozopo.warehouse.operations.GoodsTB;
import zozopo.warehouse.operations.PurchaseOS;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class GetCheckGoodsReserveForAjaxAction extends ActionSupport implements Action,SessionAware,ServletRequestAware,ServletResponseAware{
	//传入参数
	private int warehouseid;
	private int goodsid;
	private int number;

	//传出参数
	private String responseText  = "";
	HttpServletRequest request;
	HttpServletResponse response;
	private Map<Object, Object> session;
	

	private Map<String,String> addstatus;
	
	
	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		request = arg0;
	}

	public void setSession(Map arg0) {
		// TODO Auto-generated method stub
		session = arg0;
	}

	

	public void setServletResponse(HttpServletResponse arg0) {
		// TODO Auto-generated method stub
		response = arg0;
		response.setCharacterEncoding("UTF-8");
		response.setContentType("application/json; charset=UTF-8");
	}
	
	public String execute(){
		 
		PurchaseOS purchaseOS = new PurchaseOS();
		GoodsOS goodsOS = new GoodsOS(purchaseOS.getConn());
		
		int goodsReserve = purchaseOS.getGoodsReserve(warehouseid, goodsid);
		GoodsTB goods = goodsOS.getGoodsById(goodsid);
			
		if(goodsReserve < number){
			responseText=goods.getId_goods() + "," + goods.getName_goods() + "," + "库存不足!";
		}
			
		
		
		purchaseOS.releaseConnection();
		
		
		return SUCCESS;
	}


	public void setGoodsid(int goodsid) {
		this.goodsid = goodsid;
	}

	public int getWarehouseid() {
		return warehouseid;
	}

	public void setWarehouseid(int warehouseid) {
		this.warehouseid = warehouseid;
	}

	public int getNumber() {
		return number;
	}

	public void setNumber(int number) {
		this.number = number;
	}

	public int getGoodsid() {
		return goodsid;
	}

	

	public String getResponseText() {
		return responseText;
	}

	public void setResponseText(String responseText) {
		this.responseText = responseText;
	}

}
